package com.sun.androidexerciseproject.function.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

/**
 * Description:
 * File: NetWorkTest.java
 * Author: Administrator
 * Create: 2019/11/4 14:17
 */
public class NetWorkTest {
    public static void main(String[] args) {
        try {
            Enumeration<NetworkInterface> interfaceEnumeration = NetworkInterface.getNetworkInterfaces();
            while (interfaceEnumeration.hasMoreElements()) {
                NetworkInterface networkInterface = interfaceEnumeration.nextElement();
                System.out.println("networkInterface getName " + networkInterface.getName());
                System.out.println("networkInterface getDisplayName " + networkInterface.getDisplayName());
                System.out.println("networkInterface getIndex " + networkInterface.getIndex());
                System.out.println("networkInterface toString " + networkInterface.toString());
                System.out.println("networkInterface getMTU " + networkInterface.getMTU());
                Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses();
                while (inetAddressEnumeration.hasMoreElements()) {
                    InetAddress inetAddress = inetAddressEnumeration.nextElement();
                    System.out.println("networkInterface inetAddress  getCanonicalHostName " + inetAddress.getCanonicalHostName());
                    System.out.println("networkInterface inetAddress  getHostAddress " + inetAddress.getHostAddress());
                    System.out.println("networkInterface inetAddress  getHostName " + inetAddress.getHostName());
                    System.out.println("networkInterface inetAddress  toString " + inetAddress.toString());
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
}
